package com.tinno.chargelauncher.service;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

import com.tinno.chargelauncher.charge.WiredChargingAnimation;
import com.tinno.chargelauncher.receiver.MultifunctionReceiver;

/**
 * 充电监听服务
 */
public class ChargeListenerService extends Service {

	private static final String TAG = ChargeListenerService.class.getSimpleName();

	private MultifunctionReceiver mReceiver;

	@Nullable
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		Log.d(TAG, "ChargeListenerService:onCreate: onCreate !");
		initReceiver();
	}

	private void initReceiver(){
		IntentFilter filter = new IntentFilter();
		filter.addAction(Intent.ACTION_POWER_CONNECTED);
		filter.addAction(Intent.ACTION_POWER_DISCONNECTED);

		mReceiver = new MultifunctionReceiver();
		registerReceiver(mReceiver, filter);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.d(TAG, "onDestroy: ");
		if (mReceiver != null){
			unregisterReceiver(mReceiver);
		}
	}
}
